package cn.passlink.www.Security;
import cn.passlink.www.Enity.sysUser;
import cn.passlink.www.Mapper.sysUserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private sysUserDao sysUserDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //根据用户名查询用户信息
        sysUser user=sysUserDao.findByUsername(username);
        if(user==null){
            log.error("用户查询错误");
           throw new UsernameNotFoundException("用户为空");
        }
        //封装成UserDetails对象返回
        return new LoginUser(user);
    }
}
